<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

require APPPATH . '/libraries/BaseController.php';
/**
 * Class : User (UserController)
 * User Class to control all user related operations.
 * @author : Kishor Mali
 * @version : 1.1
 * @since : 15 November 2016
 */
class OrderType extends BaseController
{
    /**
     * This is default constructor of the class
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->model('user_model');
        $this->load->model('orderType_model');
        $this->isLoggedIn();   
        $this->load->helper(array('form', 'url'));
    }

    public function index(){
        $this->global['pageTitle'] = '订单类型';
        $res = $this->orderType_model->getOrderType();

        $this->loadViews("orderTypeView", $this->global, array('orderTypes' => $res) , NULL);

    }

    public function do_upload()
    {
        $config['upload_path']      = './uploads/';
        $config['allowed_types']    = 'gif|jpg|png|txt|xlsx|xls|csv';
        $config['max_size']     = 1024 * 10;
        $config['max_width']        = 1024 * 10;
        $config['max_height']       = 768 * 10;

        $this->load->library('upload', $config);
        $this->global['pageTitle'] = 'CodeInsect : Upload';

        if ( ! $this->upload->do_upload('userfile'))
        {
            $error = array('error' => $this->upload->display_errors(), 'upload_data' => $this->upload->data());

            $this->loadViews('upload/index', $this->global, $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            
            $this->loadViews('upload/upload_success', $this->global, $data);
        }
    }

    private function jsonArray($arr) {
        $a = '[';
        foreach ($arr as $key => $value) {
            $a = $a.'"'.$value.'"';
        }
        $a = $a.']';
        return $a;
    }

    public function compile_excel() {
        $this->load->library("hei_excel");
        $this->global['pageTitle'] = 'CodeInsect : Excel';
        $option = array(
            'mergeCells' => [],
            'formula' => [],
            'format'=> []
        );
        $fileName = 'test01.xlsx';
        $data = $this->hei_excel->importExcel('./uploads/'.$fileName, 0, 0, $option);
        $this->loadViews('upload/excel_view', $this->global, array(
            'data' => $data, 
            'mergeCells' => $this->jsonArray($option['mergeCells']),
            'file' => $fileName
        ));

    }

    
    
}

?>